Attribute VB_Name = "ScriptBasic"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' ScriptBasic Module
' for Visual Basic 6
'
' Copyright (C) 2001 Taras Young
'
' http://sbasic.sourceforge.net/
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Modified for NightOwl by the NightOwl Project

' This module is a small, self-contained BASIC interpreter.
' Its main purpose is to allow VB developers the flexibility
' to create small add-ons for their programs at any time, even
' after the product has been compiled and released.
'
' It also gives technically-minded end-users the opportunity
' to write their own extensions to your product, thus
' enhancing their software experience.
'
' This interpreter contains its own variable set and has a
' built-in error handler. The command set bears many
' similarities to VB, although the syntax is slightly different
' for a few commands.
' However, the basic variable manipulation (a = b + c) is the
' same, and many, commands remain unchanged, eg:
'
'    Open "c:\myfile.dat" For Input as #1
'
' and:
'
'    a = LCase("HELLO")
'
' Full documentation is available on the website.
'
'
' Internal calls you can use:
'
'     InitScript
'
'               - Initialises the interpreter.
'               - This MUST be done before any
'               - other part of this module is
'               - used.
'
'     variable = Interpret("Filename")
'eg:         a = Interpret("C:\MyFiles\script.dat")
'
'              - Runs a script and returns any
'              - results to variable.
'
'     Quick "command line"
'eg:  Quick "name=Thom"
'
'              - Parses the individual command
'              - line without loading a script.
'              - You can use a colon : in Quick
'              - mode to seperate commands:
'
'eg:  Quick "Delimit ':name='Thom':surname='Yorke':Delimit"
'
' Note the Delimit command is used here to change the
' delimiting character to ' from its default of ", so
' you don't need to use Quick "name=" + Chr(34) + "Thom" + Chr(34)...
' If you use it this way, remember to change it back
' to its default when you're finished by typing Delimit
' (with no parameters.)
'
' Have fun!
'
' Taras Young
'
' License: This software is released under the GNU GPL.
'          You use the software at your OWN RISK; it
'          comes with NO WARRANTIES.
'

'' Useful Declares ''

Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC

Declare Function GetTickCount Lib "kernel32" () As Long

Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal nCmdShow&)
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
    "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) As Long

'' --------------- ''

Public Cmd, VarNames(), VarValues(), Delimit, QuickParse, QuickDummy, _
       LineNo, Continuing, ElseIfing, OpenFiles(), ifs, Methd, _
       Fors, ForLineNos(), ForVarNames(), ForVarMax(), ForVarStep()

Public Function Interpret(WhatFile)

'On Error GoTo ErrHandle

LineNo = 0

    If QuickParse Then
     dummy = QuickDummy
     GoTo BeginQuick
    End If

'Parses and interprets a file


 Open WhatFile For Input As #1              'Open
 

  Do
   
DoCurrent:

    Line Input #1, dummy                    'Get line of input
    LineNo = LineNo + 1
  
 
BeginQuick:

Dealt = False                               'We aint dealt with
                                            'this line yet
  
  DoEvents                                  'Prevent crashes
  
''' Command Set '''

dummy = LTrim(dummy)

Do
 If Left(dummy, 1) = Chr(9) Then dummy = Mid(dummy, 2, Len(dummy))
 DoEvents
Loop Until Left(dummy, 1) <> Chr(9)

   If Part("beep ", dummy) Then
    Beep
    Dealt = True
   End If
   
   
   If Part("delimit ", dummy) Or Part("~ ", dummy) Then
   
    Cmd = Trim(Cmd)
    Cmd = VarParse(Cmd)
    
     If Cmd = "" Then Cmd = Chr(34)
     
    Delimit = Cmd
   
    Dealt = True
   End If
   
   
   If Part("out ", dummy) Then
   
    Debug.Print VarParse(Cmd)
   
   
   End If
   
   
   
   If Part("if ", dummy) Then


    If InStr(Cmd, "=") Then ch = "="
    If InStr(Cmd, "<") Then ch = "<"
    If InStr(Cmd, ">") Then ch = ">"
    If InStr(Cmd, "<=") Then ch = "<="
    If InStr(Cmd, ">=") Then ch = ">="
    If InStr(Cmd, "<>") Then ch = "<>"
   
      ifvar = Splitter(Cmd, ch, 1, True)
      compr = Splitter(Cmd, ch, 2, True)
       
        If LCase(Right(compr, 5)) = " then" Then
         compr = Left(compr, Len(compr) - 5)
        End If
   
           ifvar = VarParse(ifvar)
           compr = VarParse(compr)
   

    Continuing = False
   
        Select Case ch
         Case "="
          If ifvar = compr Then Continuing = True
         Case "<"
          If ifvar < compr Then Continuing = True
         Case ">"
          If ifvar > compr Then Continuing = True
         Case "<="
          If ifvar <= compr Then Continuing = True
         Case ">="
          If ifvar >= compr Then Continuing = True
         Case "<>"
          If ifvar <> compr Then Continuing = True
        End Select
                  
'         ifs = ifs + 1
                 
         If Not Continuing Then
         
          Do
         
            Line Input #1, dummy
            LineNo = LineNo + 1
         
              If Part("if ", dummy) Then ifs = ifs + 1
              
              If LCase(Trim(dummy)) = "end if" And ifs = 0 Then Exit Do
              If LCase(Trim(dummy)) = "else" And ifs = 0 Then Exit Do
              If Part("elseif ", dummy) And ifs = 0 Then Exit Do
              
              If LCase(Trim(dummy)) = "end if" And ifs > 0 Then ifs = ifs - 1
              
         
          Loop Until EOF(1) 'Or LCase(Trim(dummy)) = "end if" _
          Or LCase(Trim(dummy)) = "else" Or Part("elseif ", dummy)
         
         ElseIf Continuing Then
                  
         
         End If
   
   
    Dealt = True
   End If
   
      
   If Part("elseif ", dummy) And Not Continuing Then
 
     dummy = Mid(dummy, 5, Len(dummy))
   
      ElseIfing = True
      GoTo BeginQuick
   
    Dealt = True
   ElseIf Part("elseif ", dummy) And Continuing Then
   
    Do
   
     Line Input #1, dummy
     LineNo = LineNo + 1
   
    Loop Until EOF(1) Or Part("elseif ", dummy) Or _
   Part("else", dummy) Or LCase(Trim(dummy)) = "end if"
   
     Continuing = False
   
    Dealt = True
   End If
   
   
   
   If Part("else", dummy) And Continuing Then
   
   ifs = ifs + 1
   
    Do
    
     Line Input #1, dummy
       LineNo = LineNo + 1
                  
         
              If Part("if ", dummy) Then ifs = ifs + 1
              
              If LCase(Trim(dummy)) = "end if" And ifs = 0 Then Exit Do
              If Part("elseif ", dummy) And ifs = 0 Then Exit Do
              
              If LCase(Trim(dummy)) = "end if" And ifs > 0 Then ifs = ifs - 1
    
    Loop Until EOF(1)
   
     Continuing = False
   
    Dealt = True
   End If
   
   
   
   
   
   If LCase(Trim(dummy)) = "end if" Then
   
             ifs = ifs - 1

   End If
   
   
'  If Part("open ", dummy) Then
   
   
   
   
   If Part("open ", dummy) Then
   
    filenm = Splitter(Cmd, "for", 1, True)
    fileop = Splitter(Cmd, "for", 2, True)
     filenum = Splitter(fileop, "as", 2, True)
     fileop = Splitter(fileop, "as", 1, True)
    
        If Left(filenum, 1) = "#" Then filenum = Mid(filenum, 2, Len(filenum))
               
         filenm = VarParse(filenm)
         filenum = VarParse(filenum)
         fileop = LCase(fileop)
        
        filenum = Str(Val(filenum) + 1)
               
    Select Case fileop
     Case "output"
       Open filenm For Output As #Val(filenum)
     Case "input"
       Open filenm For Input As #Val(filenum)
     Case "append"
       Open filenm For Append As #Val(filenum)
     Case "binary"
       Open filenm For Binary As #Val(filenum)
     Case Else
       Open filenm For Random As #Val(filenum)
    End Select
   
   
    Dealt = True
   End If
   
   
   If Part("close ", dummy) Then
   
     If Left(Cmd, 1) = "#" Then Cmd = Mid(Cmd, 2, Len(Cmd))
     Cmd = VarParse(Cmd)
     
        Cmd = Str(Val(Cmd) + 1)
     Close #Val(Cmd)
   
    Dealt = True
   End If
   
   
   If Part("print ", dummy) Then
   
     filenum = Splitter(Cmd, ",", 1, True)
     printwh = Splitter(Cmd, ",", 2, True)
     
     filenum = VarParse(filenum)
     printwh = VarParse(printwh)
     
      If Left(filenum, 1) = "#" Then filenum = Mid(filenum, 2, Len(filenum))
      filenum = Str(Val(filenum) + 1)
     
      Print #Val(filenum), printwh
   
    Dealt = True
   End If
   
   
   If Part("input ", dummy) Then
   
     filenum = Splitter(Cmd, ",", 1, True)
     inputwh = Splitter(Cmd, ",", 2, True)
     
     filenum = VarParse(filenum)
     
      If Left(filenum, 1) = "#" Then filenum = Mid(filenum, 2, Len(filenum))
      filenum = Str(Val(filenum) + 1)
     
      Input #Val(filenum), dummy
      SetVar inputwh, dummy
   
    Dealt = True
   End If
   
   
   If Part("line input ", dummy) Then
   
     filenum = Splitter(Cmd, ",", 1, True)
     inputwh = Splitter(Cmd, ",", 2, True)
     
     filenum = VarParse(filenum)
     
      If Left(filenum, 1) = "#" Then filenum = Mid(filenum, 2, Len(filenum))
      filenum = Str(Val(filenum) + 1)
     
      Line Input #Val(filenum), dummy
      SetVar inputwh, dummy
   
    Dealt = True
   End If
   
   
   
   If Part("download ", dummy) Then
   
    whaturl = Splitter(Cmd, ",", 1, True)
    whatfnm = Splitter(Cmd, ",", 2, True)
       
       whaturl = VarParse(whaturl)
       whatfnm = VarParse(whatfnm)
       
     DownloadFile whaturl, whatfnm
       
   Dealt = True
   End If
   
   
   
   
   If Part("for ", dummy) Then
   
    Fors = Fors + 1
    
      ReDim Preserve ForVarNames(Fors)
      ReDim Preserve ForLineNos(Fors)
      ReDim Preserve ForVarMax(Fors)
      ReDim Preserve ForVarStep(Fors)
     
         'for a = 1 to 10
        
        ForVarNames(Fors) = Splitter(Cmd, "=", 1, True)
        
         part2 = Splitter(Cmd, "=", 2, True)
         fvval = Splitter(part2, "to", 1, True)
         fvmax = Splitter(part2, "to", 2, True)
        
        'step
         If Splitter(fvmax, "step", 1, True) <> "" And _
          Splitter(fvmax, "step", 2, True) <> "" Then
          
            'There is a specified step
           ForVarStep(Fors) = Val(Splitter(fvmax, "step", 2, True))
           fvmax = Splitter(fvmax, "step", 1, True)
         
         Else
         
           ForVarStep(Fors) = 1
         
         End If
        
        
        SetVar ForVarNames(Fors), fvval
        ForVarMax(Fors) = fvmax
        ForLineNos(Fors) = LineNo
        
   
    Dealt = True
   End If
   
   
   
   If Part("next ", dummy) Or LCase(Trim(dummy)) = "next" Then
   
        a = Val(GetVar(ForVarNames(Fors)))
        a = a + Val(ForVarStep(Fors))
                
    If Val(ForVarStep(Fors)) > 0 Then lessthan = False
    If Val(ForVarStep(Fors)) < 0 Then lessthan = True
                        
        If a >= Val(ForVarMax(Fors)) + Val(ForVarStep(Fors)) And Not _
        lessthan Or a <= Val(ForVarMax(Fors)) + Val(ForVarStep(Fors)) _
        And lessthan Then
        
           Fors = Fors - 1
        
        Else
           
           SetVar ForVarNames(Fors), a
            
           Close #1
           
           LineNo = 0
           
           Open WhatFile For Input As #1
           
           For n = 0 To ForLineNos(Fors) - 1
            If EOF(1) Then Close #1: Exit Function
            Line Input #1, dummy
            LineNo = LineNo + 1
           Next
           
           GoTo DoCurrent
           
        End If
        
        
   
    Dealt = True
   End If
   
      
   
   If Part("do until", dummy) Then
   
          
    Dealt = True
   End If
   
   
   
   
   If SecondPart("inputbox ", dummy) Then

       a = Splitter(dummy, "=", 1, True)
       b = VarParse(Splitter(Methd, ",", 1, True))
       c = VarParse(Splitter(Methd, ",", 2, True))

      SetVar a, InputBox(b, c)
     
    Dealt = True
   End If
  
  
   If Part("msgbox ", dummy) Then
    
     a = VarParse(Cmd)
     
      MsgBox a
    
    Dealt = True
   End If
  
  
  
   If Part("return ", dummy) Then
    
     a = VarParse(Cmd)
     
      Interpret = a
      Close #1
      Exit Function
    
    Dealt = True
   End If
   
   
   
   If SecondPart("environ ", dummy) Then
       GoSub StdSplit2
       SetVar a, Environ(b)
    Dealt = True
   End If
   
   If SecondPart("lcase ", dummy) Then
       GoSub StdSplit2
       SetVar a, LCase(b)
    Dealt = True
   End If
 
   If SecondPart("ucase ", dummy) Then
       GoSub StdSplit2
       SetVar a, UCase(b)
    Dealt = True
   End If

   If SecondPart("trim ", dummy) Then
       GoSub StdSplit2
       SetVar a, Trim(b)
    Dealt = True
   End If
  
   If SecondPart("ltrim ", dummy) Then
       GoSub StdSplit2
       SetVar a, LTrim(b)
    Dealt = True
   End If
 
   If SecondPart("rtrim ", dummy) Then
       GoSub StdSplit2
       SetVar a, RTrim(b)
    Dealt = True
   End If
 
   If Part("end", dummy) Then
    End
   End If

   If Part("settings ", dummy) Then
    CallCPL Cmd
   End If


''' /Command Set '''
 
  
'                                                   "If" Level:

If Not Dealt Then   'We may have an equation on our hands, sir!

  VarNm = Splitter(dummy, "=", 1, True) 'Var Name
  eqn = Splitter(dummy, "=", 2, True)   'Equation

    If InStr(dummy, Delimit) Then                       '*
    
     'It's a string "equation"
    
      j = "": word = "": Total = ""
        InAWord = False
        
        For n = 1 To Len(eqn)
    
            j = Mid(eqn, n, 1)
          
             If j = "+" And Not InAWord Then
              
            'Evaluate the "word":
              word = Trim(word)
              word = VarParse(word)
              Total = Total + word
              word = "": j = ""
              
             End If
    
            If j = Delimit Then         'Deal with quotes
             InAWord = Not InAWord
            End If
    
          word = word + j
    
        Next
        
            'Evaluate the tail end:
              word = Trim(word)
              word = VarParse(word)
              Total = Total + word
              word = "": j = ""
        
        
     'Send the complete string to the requested
     'variable:
        SetVar VarNm, Total
        
    
    Else                                                '*
     
     'It's a numbers equation
     
       If InStr(dummy, "=") Then                        '**
          
            If Val(eqn) = 0 Then                        '***
                    
                    If Trim(eqn) = "0" Then             '****
                     SetVar VarNm, "0"
                    Else                                '****
                          
                          If Calc(eqn) = 0 Then         '*****
                           SetVar VarNm, VarParse(eqn)
                          Else                          '*****
                           SetVar VarNm, Calc(eqn)
                          End If                        '*****
                    
                    End If                              '****
            
            Else                                        '***
          
     'Send the equated value to the requested
     'variable:
          SetVar VarNm, Calc(eqn)
       
        End If                                          '***
       
       End If                                           '**
    
    End If                                              '*

End If
  
    If QuickParse Then Exit Function
    
  
  Loop Until EOF(1)
 
 
 Close #1
 
 
 
 
 
Exit Function

StdSplit:

' command a = b

     a = Splitter(Cmd, "=", 1, True)
     b = Splitter(Cmd, "=", 2, True)
   
       b = VarParse(b)
Return

StdSplit2:

     a = Splitter(dummy, "=", 1, True)
     b = VarParse(Methd)

Return


ErrHandle:

dowhat = MsgBox("An error has occured:" + vbCrLf + vbCrLf + Err.Description + " (" + Trim(Str(Err.Number)) + ")" + vbCrLf + vbCrLf + "Error occured at line " + Trim(Str(LineNo)) + " of " + WhatFile + ":" + vbCrLf + vbCrLf + dummy + vbCrLf + vbCrLf + "Click Abort to exit - you will lose any unsaved information. Click " + vbCrLf + "Retry to try again, or Ignore to ignore the error and carry on.", vbExclamation + vbAbortRetryIgnore, App.Title)
 
Select Case dowhat
 Case vbAbort
  Close #1
  End
 Case vbRetry
  Resume
 Case vbIgnore
  Resume Next
End Select

End

End Function

Public Function SecondPart(WhatCmd, WhatSource)

' SecondPart("lcase ", "a = lcase('100')") = TRUE
' SecondPart("lcase ", "a = ucase('100')") = FALSE
'
' Returns TRUE if WhatCmd comes after the = sign
' Returns the part in brackets "('100')" in the
' variable Methd.
'

a = Splitter(WhatSource, "=", 1, True)
b = Splitter(WhatSource, "=", 2, True)

Cmd = Splitter(b, "(", 1, True)
Methd = Splitter(b, "(", 2, True)


 If Right(Methd, 1) = ")" Then Methd = Left(Methd, Len(Methd) - 1)

 If Trim(Cmd) = Trim(WhatCmd) Then
  SecondPart = True
  storein = a
 Else
  SecondPart = False
 End If


End Function

Public Sub Quick(CommandString)

'Use this to do single line commands
'from inside your program, for example,
'to set up a variable:
'
' Quick "myname = Taras"
'
'...or even:
'
' Quick "progname = " + App.ProductName
'
' AND, you can put multiple commands on one
' line using colons:
'
' Quick "Delimit ':MyName='Taras':MyFriend='Anil':Delimit"
'

 QuickParse = True
  
   
 
      j = "": word = "": Total = ""
        InAWord = False
        
        For n = 1 To Len(CommandString)
    
            j = Mid(CommandString, n, 1)
          
                 If j = ":" And Not InAWord Then
                  
                  'Interpret that bit:
                   QuickDummy = word
                   Interpret ""
            
                  word = "": j = ""
                  
                 End If
    
            If j = Delimit Then         'Deal with quotes
             InAWord = Not InAWord
            End If
    
          word = word + j
    
        Next
        
            'Interpret the tail end:
              QuickDummy = word
              Interpret ""
              
              word = "": j = ""
        
     
  
  
 QuickParse = False

End Sub

Public Function Part(b, a)

' Part("Command ", LineBeingParsed)
'
' Returns:
'    If the start of LineBeingParsed = "Command ", then
'    Part = True, else Part = False
'
'    Cmd = The remainder of LineBeingParsed (minus "Command ")
'

p = Left(a, Len(b))
If Trim(LCase(p)) = Trim(LCase(b)) Then Part = True Else Part = False
If Right(b, 1) <> " " And Len(Trim(b)) < Len(Trim(a)) Then Part = False

Cmd = Trim(Mid(a, Len(b) + 1, Len(a)))

End Function

Public Sub InitScript()

'Note: You MUST do:
' InitScript
'before using any script functions,
'otherwise errors will occur.

ReDim VarNames(0)                           '} Dim variable
ReDim VarValues(0)                          '} storage arrays

Delimit = Chr(34)                          'Set Delimiter as "

End Sub

Public Function Splitter(WhatString, DividingChars, Part_1_Or_2, TrimTrue)

'Splits a string into two parts
'
' eg:
'        a = Splitter("hello = true", "=", 1, True)
'        b = Splitter("hello = true", "=", 2, True)
'
'   a = "hello"
'   b = "true"
'


For n = 1 To Len(WhatString)

 j = Mid(WhatString, n, Len(DividingChars))
 
 If LCase(j) = LCase(DividingChars) Then
  
     If Part_1_Or_2 = 1 Then
  
       Splitter = Left(WhatString, n - 1)
       If TrimTrue Then Splitter = Trim(Splitter)
       Exit Function
     
     Else
     
       Splitter = Mid(WhatString, n + Len(DividingChars), Len(WhatString))
       If TrimTrue Then Splitter = Trim(Splitter)
       Exit Function
     
     End If
  
 End If

Next
 

End Function

Public Sub SetVar(VarName, VarValue)

'Sets/creates a variable

For n = 0 To UBound(VarNames)

 If LCase(VarNames(n)) = LCase(VarName) Then
   VarValues(n) = VarValue
   Exit Sub
 End If

Next


ReDim Preserve VarNames(UBound(VarNames) + 1)
ReDim Preserve VarValues(UBound(VarValues) + 1)

VarNames(UBound(VarNames)) = VarName
VarValues(UBound(VarValues)) = VarValue

End Sub

Public Function GetVar(VarName)

'Returns a variable

For n = 0 To UBound(VarNames)

 If LCase(VarNames(n)) = LCase(VarName) Then
   GetVar = VarValues(n)
   Exit Function
 End If

Next

GetVar = VarName

End Function

Public Function VarParse(aString)

aString = Trim(aString)

    If Left(aString, 1) = Delimit And Right(aString, 1) = Delimit Then
     
     'It's in "quotes" so don't parse, but do
     'remove quotes
     
       If Left(aString, 1) = Delimit Then aString = Mid(aString, 2, Len(aString))
       If Right(aString, 1) = Delimit Then aString = Left(aString, Len(aString) - 1)
      
      VarParse = aString
      
     Exit Function
    End If


'Parse as a variable first:

VarParse = GetVar(aString)


'Then see if it has [] around it eg [5+5/2]

 If Left(aString, 1) = "[" And Right(aString, 1) = "]" Then

   VarParse = Calc(Mid(aString, 2, Len(aString) - 1))

 End If


End Function


'''' End of the main section of the interpreter. ''''
'''' Everything after this comment is essential; ''''
'''' however, I didn't write some of it.         ''''



Public Function Calc(Math)

'
'This portion originally written by
'Andrew Rendle - http://www.andrewr.co.uk/
'

doa$ = Math

Dim trig$(3)
times = False: divide = False: plus = False: minus = False: power = False
DoSin = False: DoCos = False: DoTan = False: trigpos = 1


'On Error GoTo errhdl
EvaluateString:

For i = 1 To Len(doa$)

X$ = Mid$(doa$, i, 1)
past3$ = Right$(past3$, 2) + X$
If X$ <> "+" And X$ <> "-" And X$ <> "/" And X$ <> "*" And X$ <> "^" Then
     numnow$ = numnow$ + X$
ElseIf X$ = "+" Then
     GoSub DoOp
     times = False: divide = False: plus = True: minus = False: power = False
     numnow$ = ""
ElseIf X$ = "*" Then
     GoSub DoOp
     times = True: divide = False: plus = False: minus = False: power = False
     numnow$ = ""
ElseIf X$ = "/" Then
     GoSub DoOp
     times = False: divide = True: plus = False: minus = False: power = False
     numnow$ = ""
ElseIf X$ = "-" Then
     GoSub DoOp
     times = False: divide = False: plus = False: minus = True: power = False
     numnow$ = ""
ElseIf X$ = "^" Then
     GoSub DoOp
     times = False: divide = False: plus = False: minus = False: power = True
     numnow$ = ""
End If
Next i

GoSub DoOp

Calc = numout






Exit Function


DoOp:


If times Then
     numout = numout * Val(VarParse(numnow$))
     numnow$ = ""

ElseIf divide Then
     numout = numout / Val(VarParse(numnow$))
     numnow$ = ""
ElseIf plus Then
     numout = numout + Val(VarParse(numnow$))
     numnow$ = ""
ElseIf minus Then
     numout = numout - Val(VarParse(numnow$))
     numnow$ = ""
ElseIf power Then
     numout = numout ^ Val(VarParse(numnow$))
     numnow$ = ""
Else
     numout = Val(VarParse(numnow$))
End If
Return

errhdl:
MsgBox "Math Error: " & Err.Description + " (" + Trim(Str(Err.Number)) + ")"
Resume Next



End Function


Public Function Uptime()
'Written by Taras Young :P

'Returns uptime of computer

Total = GetTickCount
Total = Total / 1000
Total = Round(Total)

mins = Total / 60
hrs = mins / 60

mins = Round(mins)
hrs = Round(hrs)

mins = mins - (60 * hrs)

Uptime = hrs & " hours " & mins & " mins"

End Function


''' THE FOLLOWING SUBS AND FUNCTIONS WERE '''
''' FOUND ON VARIOUS FREE CODE SITES.     '''

Public Sub HideDesktop()

'Hides all icons on desktop

Dim hHandle As Long
hHandle = FindWindow("progman", vbNullString)
Call ShowWindow(hHandle, SW_HIDE)

End Sub

Public Sub ShowDesktop()

'Shows all icons on desktop

Dim hHandle As Long
hHandle = FindWindow("progman", vbNullString)
Call ShowWindow(hHandle, SW_NORMAL)

End Sub

Public Sub CallCPL(FileName)

 'Runs a CPL file (Control Panel Applet) modal
 'with your form
 
  ' Some to try:
  '   desk.cpl      -      Desktop settings
  '   inetcpl.cpl   -      Internet Control Panel
  '   joy.cpl       -      Joystick settings
  '
  ' Use find C:\Windows\System\*.cpl to
  ' find all the available ones on your system.
  '
  ' I have set up a few so it is easier to remember them
  ' below:
  '                                             --Taras
  
  Select Case FileName
   Case "internet": FileName = "inetcpl.cpl"
   Case "desktop": FileName = "desk.cpl"
   Case "joystick": FileName = "joy.cpl"
   Case "modem": FileName = "modem.cpl"
   Case "themes": FileName = "themes.cpl"
   Case "system": FileName = "sysdm.cpl"
  End Select
 
 Shell "rundll32.exe shell32.dll,Control_RunDLL " & FileName, vbNormalFocus

End Sub

Public Sub ChangeWindowCaption(CurrentCaption, NewCaption)

'Change the caption of any window

Dim target_hwnd As Long
Dim target_name As String
Dim new_caption As String
target_name = CurrentCaption
target_hwnd = FindWindow(vbNullString, target_name)
If target_hwnd = 0 Then
MsgBox "Cannot find target"
Exit Sub
End If

new_caption = NewCaption
SendMessage target_hwnd, WM_SETTEXT, 0, ByVal new_caption

End Sub

Public Function DownloadFile(URL, _
    LocalFilename) As Boolean

    Dim lngRetVal As Long
    
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    
    If lngRetVal = 0 Then DownloadFile = True

End Function


